<?php

    include_once("config.php");

    ob_start();
    include_once(INCLUDE_DIR. "/JavaScript.php");
    include_once(INCLUDE_DIR. "/Product.php");
    include_once(INCLUDE_DIR. "/Output.php");
    ob_clean();

    $title = !empty($_REQUEST["title"]) ? trim($_REQUEST["title"]) : "" ;
    $pc_pic = !empty($_REQUEST["pc_pic"]) ? trim($_REQUEST["pc_pic"]) : "" ;
    $bannerfileList = !empty($_REQUEST["bannerfileList"]) ? trim($_REQUEST["bannerfileList"]) : "" ;
    $is_online = !empty($_REQUEST["is_online"]) ? trim($_REQUEST["is_online"]) : "" ;
    $category_no = !empty($_REQUEST["category_no"]) ? trim($_REQUEST["category_no"]) : "0" ;
    $sort = !empty($_REQUEST["sort"]) ? trim($_REQUEST["sort"]) : "0" ;
    $pc_pic = !empty($_REQUEST["pc_pic"]) ? $_REQUEST["pc_pic"] : array() ;
    $wap_pic = !empty($_REQUEST["wap_pic"]) ? $_REQUEST["wap_pic"] : array() ;
    $description = !empty($_REQUEST["description"]) ? $_REQUEST["description"] : "";

    $myMySQL = new MySQL();
    $myMySQL->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

    $myProduct = new Product($myMySQL);

    $condition = "title = '". $title ."' AND category_no = $category_no";

    if( $myProduct->getCount($condition) >= 1 )
    {
       Output::error('标题不能重复！',array(), 1);
    }

    $dataArray = array();
    $dataArray['title']       = $title;
    $dataArray['add_time']    = 'now()';
    $dataArray['banner_pic']  = $bannerfileList;
    $dataArray['thumb_pic']   = $thumbfileList;
    $dataArray['category_no'] = $category_no;
    $dataArray['is_online']   = $is_online;
    $dataArray['sort']        = $sort;
    $dataArray['pc_pic']      = json_encode($pc_pic);
    $dataArray['wap_pic']     = json_encode($wap_pic);
    $dataArray['description'] = $description;

    $myProduct->addRow($dataArray);

    Output::succ('添加成功！', array());

?>